package fr.umlv.android.boggle;

import android.graphics.Color;
import android.os.CountDownTimer;
import android.widget.TextView;

public class DownTimerGame extends CountDownTimer {
	private final TextView view;
	private long countMinutes;

	
	public DownTimerGame(TextView view, long millisInFuture, long countDownInterval) {
		super(millisInFuture, countDownInterval);
		countMinutes = millisInFuture/60000;
		this.view = view;
	}

	@Override
	public void onFinish() {
		
	}

	@Override
	public void onTick(long millisUntilFinished) {
		long nbSecondes = millisUntilFinished/1000%60;
		if(nbSecondes == 0) {
			countMinutes--;
		}
		String stringSecondes = String.valueOf(nbSecondes);
		if(nbSecondes<10) {
			stringSecondes = "0" + stringSecondes;
		}
		view.setText(String.valueOf(countMinutes)+":"+stringSecondes);
		
		if(countMinutes == 0 && nbSecondes == 30) {
			view.setTextColor(Color.RED);
		}
	}
}
